#include "cardpoolviewobject.h"
#include <QGraphicsDropShadowEffect>


CardPoolViewObject::CardPoolViewObject(CardPool *cardpool)
{
    cardPoolRect = QRect(-10, -20, 60, 80);

    QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect();
//            QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect();

    this->setGraphicsEffect(effect);
    this->setFlag(QGraphicsItem::ItemIsMovable, false);

    m_CardPool = cardpool;
}

void CardPoolViewObject::paint(QPainter *painter, const QStyleOptionGraphicsItem *,
           QWidget *)
{
    QRect rect = cardPoolRect;
    painter->setPen(Qt::black);
    painter->setBrush(Qt::white);
    for (int i = 0; i < 5; ++i)
    {
        painter->setPen(Qt::black);
        painter->drawRect(rect);
        painter->setPen(Qt::red);
        painter->drawLine(rect.topLeft(), rect.bottomRight());
        painter->drawLine(rect.topRight(), rect.bottomLeft());
        rect.adjust(2, 2, 2, 2);
    }

    if (m_CardPool == NULL)
        return;
    painter->setPen(Qt::black);
    painter->drawText(rect.adjusted(5, 5, 5, 5),QString::number(m_CardPool->getCount()));
}

QRectF CardPoolViewObject::boundingRect() const
{
    return cardPoolRect.adjusted(-5, -5, 5, 5);
}

QPainterPath CardPoolViewObject::shape() const
{
    QPainterPath path;
    path.addRect(cardPoolRect);
    return path;
}

CardViewObjectData *CardPoolViewObject::getViewObjectInformation()
{
    if (m_Data == NULL)
    {
        m_Data = new CardViewObjectData();
    }

    return m_Data;
}
